//
//  WKExpiredCouponsController.m
//  WeKeTang
//
//  Created by ichina on 2017/9/13.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#import "WKExpiredCouponsController.h"
#import "WKWebViewController.h"
#import "WKExpireCell.h"

#define useRulesUrl   @"http://weixin.dezhi.com/dezhi/hongbaorules.php"

@interface WKExpiredCouponsController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIButton *BtnUseRules;

@property (weak, nonatomic) IBOutlet UITableView *mainTableView;

@property (nonatomic, strong) UIImageView *bgImageView;

@end

@implementation WKExpiredCouponsController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.navItem.title = @"优惠券";
    
    [self setupUI];
}
- (void)setupUI{
    
    NSLog(@"过期优惠券:%@",self.dataList);
    self.navgationBar.barTintColor = RGBColor(40, 188, 203);
    
    self.statusbar.backgroundColor = RGBColor(40, 188, 203);
    
    [self middleTitleColor:[UIColor whiteColor]];
    
    self.view.backgroundColor = RGBColor(245, 245, 245);
    
    [self setLeftButtonWithImage:@"icon_return_white" highlightedImage:@"icon_return_white" target:self action:@selector(backAction)];
    
    [self.BtnUseRules setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
    
    [self.BtnUseRules setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    
    [self.mainTableView registerNib:[UINib nibWithNibName:@"WKExpireCell" bundle:nil] forCellReuseIdentifier:@"ExpireCell"];
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kDeviceScreenWidth, 100)];
    
    UIButton *checkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    checkBtn.frame =CGRectMake(kDeviceScreenWidth - 140, 15, 140, 21);
    [checkBtn setTitle:@"查看可用优惠券" forState:UIControlStateNormal];
    [checkBtn setTitleColor:RGBColor(44, 186, 203) forState:UIControlStateNormal];
    [checkBtn addTarget:self action:@selector(checkBtnAction) forControlEvents:UIControlEventTouchUpInside];
    checkBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [footView addSubview:checkBtn];
    YYLabel *bottomLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0, 100 - 31, kDeviceScreenWidth, 21)];
    bottomLabel.textAlignment = NSTextAlignmentCenter;
    bottomLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    bottomLabel.font = [UIFont systemFontOfSize:12];
    bottomLabel.text = @"已加载全部内容";
    [footView addSubview:bottomLabel];
    self.mainTableView.tableFooterView = footView;

    if (self.dataList.count == 0) {
        self.mainTableView.hidden = YES;
        self.BtnUseRules.hidden = YES;
        self.bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake((kDeviceScreenWidth - 88)*0.5, (kDeviceScreenHeight - 103)*0.5, 88, 103)];
//        self.bgImageView.center = self.view.center;
        self.bgImageView.image = IMG(@"icon_youhuiquan");
        [self.view addSubview:self.bgImageView];
    }
}
#pragma mark - 使用说明
- (IBAction)BtnUseRulesAction:(UIButton *)sender {
    WKWebViewController *webVC = [[WKWebViewController alloc]init];
    webVC.urlStr = useRulesUrl;
    [self.navigationController pushViewController:webVC animated:YES];
    
}
#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static  NSString *cellIdentifier = @"ExpireCell";
    WKExpireCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        [tableView registerNib:[UINib nibWithNibName:@"WKExpireCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.model = self.dataList[indexPath.row];
    
    return cell;
}
#pragma mark - 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}

#pragma mark - 查看可用优惠券
- (void)checkBtnAction{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}


@end
